﻿Public Class frmIncidencias
    Dim acc As New clsAccidentes
    Dim Bitacora As New clsActividad
    Private Sub frmIncidencias_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ToolStrip2.Cursor = Cursors.Hand
        ToolStrip2.RenderMode = System.Windows.Forms.ToolStripRenderMode.System
        ToolStrip2.Stretch = True

        Me.lstDestino.Visible = False
        Me.lblDestino.Visible = False

        If EmpleadoID = 0 Then
            limpiaCampos()
        Else
            limpiaCampos()
            Me.txtID.Text = EmpleadoID
            Me.txtNomEmp.Text = frmModuloEmpleadosDetalle.txtPaterno.Text.Trim & " " & frmModuloEmpleadosDetalle.txtMaterno.Text.Trim & " " & frmModuloEmpleadosDetalle.txtNombre.Text.Trim
            Me.txtDepto.Text = frmModuloEmpleadosDetalle.txtDepartamento.Text

        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
    Sub limpiaCampos()
        Me.txtID.Clear()
        Me.txtNomEmp.Clear()
        Me.datfecha.Value = Now()
        Me.datHora.Value = Now()
        Me.txtLugar.Clear()
        Me.lstTipo.Text = ""
        Me.txtCausa.Text = ""
        Me.txtCobro.Text = 0
        Me.txtDepto.Clear()
        Me.txtAutobus.Clear()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


    End Sub
    Private Sub gatter()
        acc.idAccidente = (BuscarIntDatoCitra("Select max(IdAccidente) as Id FROM Accidentes")) + 1
        acc.idempleado = Me.txtID.Text
        acc.fecha = Me.datfecha.Value
        acc.Hora = Me.datHora.Value
        acc.Lugar = Me.txtLugar.Text
        acc.Responsabilidad = ""
        acc.Severidad = ""
        acc.Monto = 0
        acc.Cobro = Me.txtCobro.Text
        acc.Causa = Me.txtCausa.Text
        acc.Autobus = Me.txtAutobus.Text
        acc.Ruta = Me.txtDepto.Text
        acc.Usuario = usuarioactivo
        acc.Tipo = Me.lstTipo.Text
        acc.Reportado = "No"
        acc.Enviado = "No"
        acc.Folio = ""
        acc.Destino = Me.lstDestino.Text
        acc.FechaRegistro = datRegistro.Value


    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim lerror As Integer
        lerror = fDespliegaCatalogos(5)
        If frmCatalogos.DialogResult = Windows.Forms.DialogResult.OK Then
            strResult = frmCatalogos.Valor
            Me.txtNomEmp.Text = Trim(frmCatalogos.dgCatalogos.Rows(strResult - 1).Cells(2).Value.ToString())
            Me.txtID.Text = Trim(frmCatalogos.dgCatalogos.Rows(strResult - 1).Cells(1).Value.ToString())
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim lerror As Integer
        lerror = fDespliegaCatalogos(1)
        If frmCatalogos.DialogResult = Windows.Forms.DialogResult.OK Then
            strResult = frmCatalogos.Valor
            Me.txtDepto.Text = Trim(frmCatalogos.dgCatalogos.Rows(strResult - 1).Cells(2).Value.ToString())
        End If
    End Sub

    Private Sub lstTipo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstTipo.SelectedIndexChanged
        If Me.lstTipo.Text = "Incidencia" Then
            Me.lstDestino.Visible = True
            Me.lblDestino.Visible = True
        Else
            Me.lstDestino.Visible = False
            Me.lblDestino.Visible = False
        End If
    End Sub

    Private Sub toolGuardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub toolSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub ToolStripButton5_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton5.Click
        If Me.txtID.Text = "" Then
            MsgBox("Debes indicar un empleado", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.txtDepto.Text = "" Then
            MsgBox("Debes indicar un departamento", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.txtAutobus.Text = "" Then
            MsgBox("Debes indicar un numero economico", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.txtLugar.Text = "" Then
            MsgBox("Debes indicar el lugar del incidente", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.lstTipo.Text = "" Then
            MsgBox("Debes indicar el tipo de incidente", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.txtCausa.Text = "" Then
            MsgBox("Debes indicar la causa del incidente", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.lstDestino.Text = "" Then
            If Me.lstDestino.Visible = True Then
                MsgBox("Debes indicar el destino del incidente", MsgBoxStyle.Exclamation, "Aviso")
                Exit Sub
            End If
        End If

        If Me.txtCobro.Text = "" Then
            Me.txtCobro.Text = 0
        End If
        gatter()

        acc.Insertar()
        Bitacora.RegistraActividad("Registró un cargo nuevo a " & txtNomEmp.Text.Trim)

        frmModuloEmpleadosDetalle.cargaAccidentes()
        Close()


    End Sub

    Private Sub ToolStripButton1_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton1.Click
        Close()

    End Sub
End Class